<%@page import="com.surelution.projects.crm.Market"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>
<g:set var="entityName" value="${message(code: 'market.label', default: 'Market')}" />
<g:javascript library="jquery"/>
<resource:dateChooser />
<link rel="stylesheet" href="${resource(dir:'css',file:'defaultTheme.css')}" />
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.fixedheadertable.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/jquery',file:'jquery.printElement.min.js')}"></script>
<script type="text/javascript" src="${resource(dir:'js/datechooser',file:'datechooser.js')}"></script>
<title>${message(code: 'market.analysis.label', default: 'analysis')}</title>
	<script type="text/javascript">
		$(document).ready(function() {
		   $("#simplePrint").click(function() {
		       printElem({leaveOpen: true, printMode: 'popup', overrideElementCSS: ["${resource(dir:'plugins/richui-0.8/css',file:'calendarmonthview.css')}","${resource(dir:'css',file:'main.css')}"]});
		   });
		   $('#myTable01').fixedHeaderTable({ footer: false, cloneHeadToFoot: false, autoShow: true });
		});
		function printElem(options){
		    $('#monthReport').printElement(options);
		};
		
	</script>
</head>

<body>
  <div class="body">
          <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
          </div>
          <div>
            <p style="font-size:16px;color:#000;margin:10px 0;">${message(code: 'market.analysis.label', default: 'analysis')}</p>
        	<g:form action="analysis">
        		选择对比月份： <g:datePicker name="endDay" precision="month" value="${endDay}" />和<g:datePicker name="startDay" precision="month" value="${startDay}" />
        		<span class="menuButton" style="margin-right:5px;"><g:actionSubmit value="${message(code: 'default.button.search.label', default: '查询')}" action="analysis"/></span>
	    		<input type="button" value="打印报表" id="simplePrint" />
			    <span class="menuButton"><g:actionSubmit value="${message(code: 'default.button.export.label', default: 'Export')}" action="exportAnalysis"/></span><br>
     			 选择持卡性质：
	    		<g:checkBox id="cardType.id_A" name="cardType"  value="A" checked="${cardType!=[]?cardType.contains('A'):true}"/><label for="cardType.id_A">领导级(A)</label>&nbsp;
	    		<g:checkBox id="cardType.id_B" name="cardType"  value="B" checked="${cardType!=[]?cardType.contains('B'):true}"/><label for="cardType.id_B">部门级(B)</label>&nbsp;
	    		<g:checkBox id="cardType.id_C" name="cardType" value="C" checked="${cardType!=[]?cardType.contains('C'):true}"/><label for="cardType.id_C">站级(C)</label>&nbsp;
        		&nbsp;&nbsp;筛选出负增长率大于30%的客户<br>
     			<sec:ifAnyGranted roles="ROLE_ADMIN">
        		 选择片区：
        		 <g:each in="${com.surelution.projects.crm.StationArea.list()}" var="area">
	    			<g:checkBox id="stationArea.id_${area.id }" name="stationArea" value="${area.id }" checked="${stationArea!=[]?stationArea.contains(area.id):true}"/><label for="stationArea.id_${area.id }">${area.areaName}</label>&nbsp;
    			</g:each>	
    			</sec:ifAnyGranted>
			    
    		</g:form>
			<g:if test="${flash.message}">
            	<div class="message">${flash.message}</div>
            </g:if>
        </div>
        
        <div id="monthReport" style="height:650px;overflow:auto;">
			<label style="font-size:16px;color:#0f3072;">对比月份：  ${endDay.format("yyyy年MM月")}和${startDay.format("yyyy年MM月")} </label>
        		<table id="myTable01">
	        		<tr>
	        			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">片区</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">客户名称</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">持卡性质</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">${endDay.format("MM月") }购油量(吨)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">${startDay.format("MM月") }购油量(吨)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">差量</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">增长率(%)</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">联系电话</td>
	          			<td style="text-align: center;vertical-align: middle;background:#75746a;color:#fff;">最近一次回访时间</td>
	    			</tr>
    				<g:each in="${result}" var="r" status="i">
					<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
    					<td style="text-align:center;">${r[0].area.areaName}</td>
    					<td style="text-align:center;"><g:link action="show" id="${r[0].id}">${r[0].name}</g:link></td>
    					<td style="text-align:center;">${r[0].cardType}</td>
    					<td style="text-align:center;"><g:formatNumber number="${r[2]}" type="number" maxFractionDigits="3" /></td>
    					<td style="text-align:center;"><g:formatNumber number="${r[1]}" type="number" maxFractionDigits="3" /></td>
    					<td style="text-align:center;"><g:formatNumber number="${r[3]}" type="number" maxFractionDigits="3" /></td>
    					<td style="text-align:center;"><g:formatNumber number="${r[4] * 100}" type="number" maxFractionDigits="1" /></td>
    					<td style="text-align:center;">${r[0].managerTel}</td>
    					<td style="text-align:center;">
    						<g:if test="${r[5]}">
    							<g:link class="search" controller="marketTracking" action="search" id="${r[0].id}">${r[5]}</g:link>
    						</g:if>
    						<g:if test="${!r[5]}">无	</g:if>
    					</td>
    				</tr>
    				</g:each>
          	</table>
        </div>

  </div>
</body>
</html>